//
//  SettingManager.m
//  MHO
//
//  Created by Hien NV on 6/18/14.
//  Copyright (c) 2014 maihoang. All rights reserved.
//

#import "SettingManager.h"
#import "Lib.h"

@interface SettingManager ()
@property (nonatomic, strong) NSArray*  data;

@end

@implementation SettingManager
+ (SettingManager*)shared {
    static SettingManager* m_settingMn = nil;
    
    @synchronized(self) {
        m_settingMn = [[self alloc] init];
    }
    return m_settingMn;
}

- (id)init {
    if (self = [super init]) {
        self.data = @[@"wifionly", @"deleteAfterDownload", @"autoInstall", @"unlockScreen", @"tietkiemluuluong", @"soundalert", @"updateCount"];
        
        NSString* first = [Lib stringForKey:@"first_runabc"] ;
        if (!first) {
            [Lib setString:@"yes" forKey:@"first_runabc"];
            BOOL values[] = {
                YES, NO, YES, YES, YES, NO, NO
            };
            for (int it = 0; it < self.data.count; it++) {
                [self setSettingAtIndex:it value:values[it]];
            }
        }
        
    }
    return self;
}

- (BOOL)settingAtIndex:(NSInteger)index {
    return [[NSUserDefaults standardUserDefaults] boolForKey:self.data[index]];
}

- (void)setSettingAtIndex:(NSInteger)index value:(BOOL)value {
    [[NSUserDefaults standardUserDefaults] setBool:value forKey:self.data[index]];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


@end
